package com.baizhi.action;

import com.baizhi.entity.Record;
import com.baizhi.entity.User;
import com.baizhi.service.RecordService;
import com.baizhi.service.impl.RecordServiceImpl;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpSession;
import java.util.List;

public class RecordAction {
    private RecordService rs = new RecordServiceImpl();
    private Record record;
    private List<Record> records;

    public String insert(){
        HttpSession session = ServletActionContext.getRequest().getSession();
        User user = (User)session.getAttribute("user");
        Record r = new Record(null, user.getUserId(), this.record.getAuctionId(), "", this.record.getAuctionPrice());
        rs.insert(r);
        return "insert";
    }

    public String selectByAuctionId(){
        HttpSession session = ServletActionContext.getRequest().getSession();
        int auctionId = (int)session.getAttribute("auctionId");
        records = rs.selectByAuctionId(auctionId);
        return "selectByAuctionId";
    }

    public Record getRecord() {
        return record;
    }

    public void setRecord(Record record) {
        this.record = record;
    }

    public List<Record> getRecords() {
        return records;
    }

    public void setRecords(List<Record> records) {
        this.records = records;
    }
}
